from IPython import display
display.Image('team.png', width=700)
Slides: github.com/hainm/amber_meeting_2016
pytraj: github.com/Amber-MD/pytraj
display.Image('./old_work_flow.jpg')
Simpler workflow?
Not a professional programmer but still want to write cool analysis in Python and make it as fast as c++? (ask Dan?)
Read new trajectory format that cpptraj does not support? (write XTC file parser with 3 lines of codes?)
Write parallel code for analysis? (Hint: how we can make parallel calculation with only one line of code?)
Interface with other programs? (pyrosetta, rdkit, cclib, …)
Nope
from numba import jit
from numpy import arange
# jit decorator tells Numba to compile this function.
# The argument types will be inferred by Numba when function is called.
@jit # make the code as fast as C/C++
def sum2d(arr):
M, N = arr.shape
result = 0.0
for i in range(M):
for j in range(N):
result += arr[i,j]
return result
# data: http://www.amber.utah.edu/AMBER-workshop/London-2015/DNA-tutorial/
import pytraj as pt
traj0 = pt.load('md.nc', 'dna.prmtop')
traj0
traj = traj0.autoimage()['!:WAT']
traj
# compute rmsd and convert raw data to pandas' DataFrame
data = pt.rmsd(traj, ref=0, mask=':1-24&!@H=', dtype='dataframe')
data.head(10)
%matplotlib inline
data.plot()
import seaborn, warnings
warnings.filterwarnings('ignore')
data.hist()
traj = pt.iterload(['tz2.0.nc', 'tz2.1.nc', 'tz2.2.nc'], 'tz2.parm7')
# multiprocessing
data = pt.pmap(pt.rmsd, traj, ref=0, mask='@CA', n_cores=8)
# MPI
# data = pt.pmap_mpi(pt.rmsd, traj, ref=0, mask='@CA')
# run: mpirun -n 8 python your_code.py
# serial: data = pt.rmsd(traj, ref=0, mask='@CA')
def method(traj, mask, ...):
for frame in traj:
dosome_thing_fun(frame)
...
return data
pt.pmap(method, traj, mask, ..., n_cores=8)
# TB of data? no problem
# write serial code in Cpptraj? no problem
from IPython import display
display.Image('bench_pmap_casegroup.png', width=600)
traj2 = pt.iterload('tz2.nc', 'tz2.parm7')
energies = pt.energy_decomposition(traj2, igb=8, dtype='dataframe')
energies[['bond', 'angle', 'dihedral', 'gb']].head(6)
# wanna make the caculation faster?
# energies = pt.pmap(pt.energy_decomposition, traj2, igb=8, n_cores=8)
# XTC
# amber.conda install mdtraj # 10 second to install
import mdtraj as md
t0 = md.load('monolayer.xtc', top='monolayer.pdb')
coordinates = t0.xyz.astype('f8')
traj = pt.Trajectory(xyz=coordinates, top='monolayer.pdb')
pt.center_of_mass(traj)
Non official manual: amber-md.github.io/pytraj
help(pt.calc_center_of_mass)
amber.pip install nglview
display.Image('./3pqr_nglview.png')
display.Image('./trpzip2_nglview.png')